package com.ruoyi.rsikManage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.PageParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.rsikManage.domain.TAlgoScenario;
import com.ruoyi.rsikManage.service.ITAlgoScenarioService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 算法场景描述Controller
 *
 * @author sxygsj
 * @date 2024-05-06
 */
@RestController
@RequestMapping("/rsikManage/scenario")
public class TAlgoScenarioController extends BaseController
{
    @Autowired
    private ITAlgoScenarioService tAlgoScenarioService;

    /**
     * 查询算法场景描述列表
     */
//    //@PreAuthorize("@ss.hasPermi('rsikManage:scenario:list')")
    @GetMapping("/list")
    public TableDataInfo list(TAlgoScenario tAlgoScenario)
    {
        startPage();
        List<TAlgoScenario> list = tAlgoScenarioService.selectTAlgoScenarioList(tAlgoScenario);
        return getDataTable(list);
    }



    @GetMapping("details/list")
    public TableDataInfo selectdetailsList(TAlgoScenario tAlgoScenario, PageParam pageParam)
    {
        setPageParam(pageParam);
        int row = tAlgoScenarioService.countAlgoScenarios(tAlgoScenario);
        List<TAlgoScenario> list = tAlgoScenarioService.selectdetailsList(tAlgoScenario,pageParam);
        TableDataInfo dataTable = getDataTable(list);
        dataTable.setTotal(row);
        return dataTable;
    }

    /**
     * 导出算法场景描述列表
     */
    //@PreAuthorize("@ss.hasPermi('rsikManage:scenario:export')")
    @Log(title = "算法场景描述", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TAlgoScenario tAlgoScenario)
    {
        List<TAlgoScenario> list = tAlgoScenarioService.selectTAlgoScenarioList(tAlgoScenario);
        ExcelUtil<TAlgoScenario> util = new ExcelUtil<TAlgoScenario>(TAlgoScenario.class);
        util.exportExcel(response, list, "算法场景描述数据");
    }

    /**
     * 获取算法场景描述详细信息
     */
    //@PreAuthorize("@ss.hasPermi('rsikManage:scenario:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tAlgoScenarioService.selectTAlgoScenarioById(id));
    }

    /**
     * 新增算法场景描述
     */
    //@PreAuthorize("@ss.hasPermi('rsikManage:scenario:add')")
    @Log(title = "算法场景描述", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAlgoScenario tAlgoScenario)
    {
        return toAjax(tAlgoScenarioService.insertTAlgoScenario(tAlgoScenario));
    }

    /**
     * 新增算法场景描述 V2
     * 自定义配置算法新增V2
     */
    //@PreAuthorize("@ss.hasPermi('rsikManage:scenario:add')")
    @Log(title = "算法场景描述", businessType = BusinessType.INSERT)
    @PostMapping("/insert")
    public AjaxResult insertV2(@RequestBody TAlgoScenario tAlgoScenario)
    {
        return toAjax(tAlgoScenarioService.insertTAlgoScenarioV2(tAlgoScenario));
    }

    /**
     * 修改算法场景描述
     */
    //@PreAuthorize("@ss.hasPermi('rsikManage:scenario:edit')")
    //@Log(title = "算法场景描述", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAlgoScenario tAlgoScenario)
    {
        return toAjax(tAlgoScenarioService.updateTAlgoScenario(tAlgoScenario));
    }

    /**
     * 删除算法场景描述
     */
    //@PreAuthorize("@ss.hasPermi('rsikManage:scenario:remove')")
    //@Log(title = "算法场景描述", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tAlgoScenarioService.deleteTAlgoScenarioByIds(ids));
    }
}
